#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"

int main(int argc, char* argv[])
{
  if(argc != 3)
  {
    std::cout << "命令行参数使用错误！" << std::endl;
    std::cout << "argv[1] 是需要解压缩的文件" << std::endl;
    std::cout << "argv[2] 是解压后的新文件名" << std::endl;
    return -1;
  }
  std::string ifilename = argv[1];
  std::string ofilename = argv[2];

  std::string body;

  std::ifstream ifs;
  ifs.open(ifilename, std::ios::binary);
  ifs.seekg(0, std::ios::end);
  size_t fsz = ifs.tellg();
  ifs.seekg(0, std::ios::beg);
  body.resize(fsz);
  ifs.read(&body[0], body.size());

  std::string unpacked = bundle::unpack(body);

  std::ofstream ofs;
  ofs.open(ofilename, std::ios::binary);
  ofs.write(&unpacked[0], unpacked.size());

  ifs.close();
  ofs.close();
  return 0;
}
